Introduction to Matrices

Introduction

Matrices are one of the most useful tools in mathematics. You can think of a matrix as nothing more than a structured way to store numbers—a data table.

If you know basic algebra, you already have everything you need to begin.

What Is a Matrix?

A matrix is a rectangular grid of numbers. For example: $$\begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}$$ Key ideas:

You can think of a matrix as:

Matrices as Data Structures

Matrices are not just mathematical objects—they are containers.

They can store:

Examples of matrices as data structures:

Matrices help us:

Matrix Notation and Terminology

Some gentle notation:

Example:

If $$A = \begin{pmatrix} 7 & 8 \\ 9 & 10 \end{pmatrix}$$ Then:

Matrix Addition

You can only add matrices of the same size.

Add them entry‑by‑entry: $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix} = \begin{pmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{pmatrix} = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix}$$

Scalar Multiplication

Multiply every entry by the same number: $$3 \begin{pmatrix} 2 & 1 \\ 0 & -1 \end{pmatrix} = \begin{pmatrix} 6 & 3 \\ 0 & -3 \end{pmatrix}$$ These operations mirror how you might scale or combine data tables.

Why Matrices Matter

Matrices are everywhere:

They allow us to:

Even at a beginner level, matrices give you a powerful new way to think about information.

Calculator

Matrices as sets of rows

  • Matrices can be written literally as a set of rows:
A = [[1, 2], [3, 4]] A = [1, 2, 3; 4, 5, 6]

Matrices from vectors

  • We can also create matrices from sets of row or column vectors:
A = matrixFromColumns([1, 2], [3,4]) A = matrixFromRows([1, 2], [3,4])

Matrices from functions

  • Instead of defining each value separately, we can specify a function for initializing values.
  • The function is run for every entry, and passed the index as it's only parameter.
A = matrixFromFunction(size, fn) A = matrixFromFunction([3,3], f(I) = random()) A = matrixFromFunction([3,3], f(I) = I[1]==I[2] ? 1 : 0)

Matric addition and scalar multiplication

  • Addition and scalar multiplication is done like any other data type:
[1, 2; 3, 4] + [5, 6; 7, 8] 5 * [1, 0; 0, 1]

Exercises

  1. Identify the size (rows and columns) of the matrix $$\begin{pmatrix} 3 & 1 & 4 \\ 1 & 5 & 9 \end{pmatrix}$$

    Solution

    The matrix has 2 rows and 3 columns, so it is a $2 \times 3$ matrix.
  2. Compute $$2\begin{pmatrix} 1 & 0 \\ -1 & 3 \end{pmatrix}$$

    Solution

    $$2\begin{pmatrix} 1 & 0 \\ -1 & 3 \end{pmatrix} = \begin{pmatrix} 2 & 0 \\ -2 & 6 \end{pmatrix}$$
  3. Add the matrices $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 4 & 3 \\ 2 & 1 \end{pmatrix}$$

    Solution

    $$\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} + \begin{pmatrix} 4 & 3 \\ 2 & 1 \end{pmatrix} = \begin{pmatrix} 5 & 5 \\ 5 & 5 \end{pmatrix}$$
  4. True or false: You can add a $2 \times 3$ matrix to a $3 \times 2$ matrix.

    Solution

    False. Matrix addition requires both matrices to have the same size.
  5. Find the entry in row 2, column 3 of $$\begin{pmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{pmatrix}$$

    Solution

    The entry in row 2, column 3 is 8.
  6. Multiply the matrix $$\begin{pmatrix} 2 & -1 \\ 0 & 4 \end{pmatrix}$$ by $-3$.

    Solution

    $$-3\begin{pmatrix} 2 & -1 \\ 0 & 4 \end{pmatrix} = \begin{pmatrix} -6 & 3 \\ 0 & -12 \end{pmatrix}$$
  7. Describe in words what a matrix is used for.

    Solution

    A matrix is a structured table of numbers used to organize, store, and manipulate data.